from apps.common.base.serializers import *
from apps.system.user.models import *


class UserBaseSerializer(BaseSerializer):
    class Meta:
        model = User
        fields = "__all__"


class UserModelSerializer(UserBaseSerializer):

    class Meta:
        model = User
        fields = "__all__"

class UserTreeModelSerializer(serializers.ModelSerializer):

    children = serializers.SerializerMethodField()
    def get_children(self, obj):
        return [{}]

    label = serializers.SerializerMethodField()
    def get_label(self, obj):
        return obj.code + ' - ' + obj.phone + ' - ' + (obj.rank.name if obj.rank else '') + ((' - ' + obj.nickname) if obj.nickname else '')

    class Meta:
        model = User
        fields = ('id', 'code', 'phone', 'nickname', 'realname', 'label', 'children')